package com.sh.data.engine.common.exception;

import com.sh.data.engine.common.constants.HttpStatus;
import com.sh.data.engine.common.constants.code.BizCode;
import com.sh.data.engine.common.constants.code.BizCodes;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 数据集成引擎异常的基类
 *
 * @author: mengzheng.mhc
 * @date: 2024/5/24 11:52
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class BusinessException extends RuntimeException {

    /**
     * 错误代码
     */
    private final int code;

    /**
     * HTTP状态码
     */
    private final int httpStatusCode;

    public BusinessException(BizCode bizCode, HttpStatus httpStatus) {
        super(bizCode.getMessage());
        this.code = bizCode.getCode();
        this.httpStatusCode = httpStatus.value();
    }

    public BusinessException(String message, BizCode bizCode, HttpStatus httpStatus) {
        super(message);
        this.code = bizCode.getCode();
        this.httpStatusCode = httpStatus.value();
    }

    public BusinessException(String message, HttpStatus httpStatus) {
        super(message);
        this.code = BizCodes.INTERNAL_SERVER_ERROR.getCode();
        this.httpStatusCode = httpStatus.value();
    }

    public BusinessException(Throwable e) {
        super(e);
        this.code = BizCodes.INTERNAL_SERVER_ERROR.getCode();
        this.httpStatusCode = HttpStatus.INTERNAL_SERVER_ERROR.value();
    }

    public BusinessException(String message) {
        super(message);
        this.code = BizCodes.INTERNAL_SERVER_ERROR.getCode();
        this.httpStatusCode = HttpStatus.INTERNAL_SERVER_ERROR.value();
    }
}
